package package007.section005

import fundation.gsonPrintln
import org.junit.Test


/**
 * @author futao
 * Created on 2017/11/15 - 15:46.
 */
class Email {}

fun loadEmail(person: Person): List<Email> {
    gsonPrintln("loading Email for ${person.name}")
    return listOf(Email())
}

class Person(val name: String) {

    private var _emails: List<Email>? = null

    val emails: List<Email>
        get() {
            if (_emails == null) {
                _emails = loadEmail(this)
            }
            return _emails!!
        }

    val emails2 by lazy { loadEmail(this) }
}

class TestClass {
    @Test
    fun testCase001() {

        val person = Person("bigMan")
        gsonPrintln("00000000000000")
        person.emails
        gsonPrintln("1111111111111")
        person.emails
        person.emails
        println("===============")
        val person2 = Person("bigMan")
        gsonPrintln("00000000000000")
        person2.emails2
        gsonPrintln("1111111111111")
        person2.emails2
        person2.emails2

    }
}


class ForTest() {
    fun test() {
        User01("shuai", 18, 2).apply {

        }
    }
}

class User01 {
    private val name: String
    private var age: Int
    private val sex: Int

    /**
     * 二级构造函数
     */
    constructor(name: String, age: Int, sex: Int) {
        this.name = name
        this.age = age
        this.sex = sex
    }
}
//
//class class01:User01(){
//
//    private val name: String
//    private var age: Int
//    private val sex: Int
//    constructor(name: String,age: Int,sex: Int) : super(name, age, sex) {
//        this.name=name
//        this.age=age
//        this.sex=sex
//    }
//}




/**
 * 主构造函数
 */
class User02 constructor(_name: String, _age: Int, _sex: Int) {
    private val name = _name
    private var age = _age
    private val sex = _sex
}

/**
 * 主构造函数，省略constructor
 * 省略花括号内的属性声明
 */
class User03(val name: String, var age: Int, val sex: Int)

/**
 * 在初始化语句块内
 */
open class User04 constructor(name: String, age: Int, sex: Int) {
    private val name: String
    private var age: Int
    private val sex: Int

    init {
        this.name = name
        this.age = age
        this.sex = sex
    }
}

class User05 constructor(name: String, age: Int, sex: Int):User04(name, age, sex){
//    private val name:String
//    init {
//        this.name=name
//    }
}

class TestCase003{
    @Test
    fun testCase001(){
        val user05 = User05(",,,", 666, 555)
        val user04 = User04("", 1, 2)
        val user02 = User02("", 1, 2)
        val user01 = User01("", 1, 2)
        gsonPrintln(user01) 
    }
}
